package com.example.njupt.helper;

import android.graphics.Color;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

/**
 * Author:      mwang
 * Create Date: Created in 2021/5/31 20:27
 * Update Date:
 * Modified By:
 * Description:
 */
public class StatusBarHelper {

    public StatusBarHelper() {
    }

    private static class StatusBarHolder {
        public static final StatusBarHelper instance = new StatusBarHelper();
    }

    public static StatusBarHelper getInstance() {
        return StatusBarHolder.instance;
    }

    public void setStatusBarFontColor(Window window, boolean isDark) {
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        View decor = window.getDecorView();

        if (isDark) {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
    }
}
